﻿<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" MasterPageFile="~/Views/Shared/Site.Master" %>

<asp:Content runat="server" ID="PageTitle" ContentPlaceHolderID="PageTitle">
    <title>工作日志</title>
</asp:Content>
<asp:Content runat="server" ID="PageStyles" ContentPlaceHolderID="PageStyles">
    <link href="../../Content/project/project.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/project/project.workitemlist.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/ui.button.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/table_jui.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #menu-finishWorkitem
        {
            width: 160px;
        }
        .divExp
        {
            border-bottom: 1px solid #ccc;
            margin-top: 15px;
        }
        
        .workitem-finished
        {
            margin-bottom: 4px;
            font-size: 14px;
            word-break: break-all;
            word-wrap: break-word;
        }
        .workitem-unfinished
        {
            margin-bottom: 4px;
            font-size: 12px;
            color: #848484;
            word-break: break-all;
            word-wrap: break-word;
        }
        
        .title
        {
            max-width: 190px;
            margin-left: 4px;
            padding-left: 3px;
            display: inline-block;
        }
        .txtProjectName
        {
            color: #666;
        }
        .txtDisabled
        {
            color: #848484;
        }
        .workitemInfo
        {
            color: #848484;
            padding-right: 3px;
            display: inline-block;
            float: right;
        }
        
        
        #txtDailyWork
        {
            font-size: 14px;
            width: 450px;
        }
        #txtDailyWork:hover
        {
            background-color: #FFFFAA;
        }
        .dataTables_wrapper
        {
            min-height: 50px;
        }
    </style>
</asp:Content>
<asp:Content runat="server" ID="PageScripts" ContentPlaceHolderID="PageScripts">
    <script src="../../Scripts/jquery.dataTables.js" type="text/javascript"></script>
    <script type="text/javascript">
    //************* URL常量
    var URL_DO_ADD_FINISHED_WORKITEM = '/project/DoAddFinishedWorkItem';

    //************* 全局变量

    var g_Var = {
        "time": null,
        "isEdited": false,
        "currentUserId": null,
    };

var StaticResource = {};

//************* 常量定义


//************* Accessor访问器
var EzAccessor = {};

function CreateAccessor() {
    if (ezmock.IS_MOCKED) {
        EzAccessor = CreateMockEzAccessor();

    } else {
        EzAccessor = CreateRealEzAccessor();
    }
}


function CreateMockEzAccessor() {
    //模拟实现服务器交互方法

    var mockEzAccessor = {

};

return mockEzAccessor;
}

function CreateRealEzAccessor() {
    //实现服务器交互方法
    var realEzAccessor = {
        "getTime" : function() {
             return <%= WebJsonExtension.ToJson(Model.Time) %>;  
        },
        "getIsFuture": function() {
            return <%= WebJsonExtension.ToJson(Model.IsFuture) %>;  
        },
        "getIsDisplayUnfinishedWorkitems": function() {
            return <%= WebJsonExtension.ToJson(Model.IsDisplayUnfinishedWorkitems) %>;  
        },
         "getDailyWork": function() {
            return <%= WebJsonExtension.ToJson(Model.DailyWork) %>;  
        }
    };
    return realEzAccessor;
};

var finishAargs = {
    GetWorkitemListService: EzDesk.Service.OwnDailyFinishedWorkitems_Sync,
    //rootElement: '#divMyWorkitems',
    myConvertor: [" ", "内容", "完成时间"]
};

var unfinishAargs = {
    GetWorkitemListService: function(callback){
        EzDesk.Service.GetWorkItems_Sync(callback,{ isMine: true, isMyAssign: false, isFinish: false });
    },
    //rootElement: '#divNeedToDo',
    myConvertor:  [" ", "内容", "到期", "负责人", "操作"],
    finishWorkitemCallBack: function(){
        $('#divMyWorkitems').workitemList(finishAargs);    
    }
};
    
function  bindWorkitemsFinished(workitemId){
    finishAargs.actionArgs = {dateTime: g_Var.time};
    $('#divMyWorkitems').workitemList(finishAargs);    
    $('#divMyWorkitems').workitemList('Highlight', workitemId, 5000);  
}

function  bindWorkitemsUnfinished(){
   
    $('#divNeedToDo').workitemList(unfinishAargs);
    
}


function bindDailyTitle (date) {
    var dateEpoch = Date.fromEpoch(date).toFullDate();
    $('#txtDailyTitle').html(dateEpoch + " " + "工作日志");
}


function bindDailyWork(dailyWork){
    if(dailyWork.htmlEncode().trim() !=  ""){
        $('#txtDailyWork').html(dailyWork);
    }   
    else {
        $('#txtDailyWork').html('单击此处添加日志');
    } 
}

//初始化页面
function initPage() {
    CreateAccessor();
    
    EzTipsManager.addTipBox('#tip_Remind', 'tipRemind');
    EzTipsManager.showTipBox('tipRemind');

    var isFuture = EzAccessor.getIsFuture();
    if (!isFuture){
        g_Var["time"] = EzAccessor.getTime();
        bindDailyTitle(g_Var["time"]);
        //当日日志
        var dailyWork = EzAccessor.getDailyWork();
        bindDailyWork(dailyWork);
        //当日完成任务
        bindWorkitemsFinished();
        //当日未完成任务
        var isDisplayUnfinishedWorkitems = EzAccessor.getIsDisplayUnfinishedWorkitems();
        if(isDisplayUnfinishedWorkitems) {
            $('.txt-unfinished-workitem').show();

            bindWorkitemsUnfinished();
            $('#nextDay').hide();
            $('#divAddWorkItem').show(); 
        }
        
    }else{
        //todo: 
    }
}


function getIsDailyWorkEmpty(){
    var isDailyWorkEmpty = false;
    if($('#txtDailyWork').html() == "单击此处添加日志"){
        isDailyWorkEmpty = true;    
    }

    return isDailyWorkEmpty;
}

//初始化事件
function initPageEvent() {
     $('#preDay').click(function () {
            var date = Date.fromEpoch(g_Var["time"]);
            var perDay = new Date(
                date.getFullYear(),
                date.getMonth(),
                date.getDate() - 1,
                0,
                0,
                0
            ).toEpoch();

            window.location.href = "/project/DailyWork?time="
                           + perDay;

        });


        $('#nextDay').click(function () {
            var date = Date.fromEpoch(g_Var["time"]);
            var nextDay = new Date(
                date.getFullYear(),
                date.getMonth(),
                date.getDate() + 1,
                0,
                0,
                0
            ).toEpoch();

            window.location.href = "/project/DailyWork?time=" + nextDay;

        });

        $('#addFinishedWorkitem').click( function () {
            var currentUser = null;
            EzDesk.Service.GetCurrentUser_CacheSync(function(e) {
                currentUser = e;
            })
            if (WorkitemCreatorSimple) {
                    WorkitemCreatorSimple.Show(false, URL_DO_ADD_FINISHED_WORKITEM, null, currentUser);
                    WorkitemCreatorSimple.SubmitSuccessCallback = function (workitemId) {
                        EzDesk.Service.OwnDailyFinishedWorkitems_Sync(function () {
                            bindWorkitemsFinished(workitemId);
                        });
                    }
                }
        });

        $('#txtDailyWork').click(function (){
            $(this).hide();
            $('.divExp').show();

            if(getIsDailyWorkEmpty() == false) {
                $('#template').val($('#txtDailyWork').html().htmlEncode().trim());    
            }
            $('#template').select();
        });

        $('#btnCancel').click(function (){
            $('#txtDailyWork').show();
            $('.divExp').hide();
            $('#template').clearFields();
        });

        $('#btnSumbit').click(function (){
            $('#txtDailyWork').show();
            $('.divExp').hide();
            //提交日志
            dailyWorkContent = $('#template').val().htmlEncode().trim();
            
            EzDesk.Service.DoUpdateDailyWork(
                function(e){
                    $.displayStatusInfo(e);
                    if(dailyWorkContent == ""){
                        $('#txtDailyWork').html("单击此处添加日志");
                    }else{
                        $('#txtDailyWork').html(dailyWorkContent);
                    }
                    $('#template').clearFields();
                }
               ,{datetime:g_Var['time'],dailyWorkContent:dailyWorkContent});
        });

    }

$(function () {
    initPage();
    initPageEvent();
});
    </script>
</asp:Content>
<asp:Content ContentPlaceHolderID="PageHead" runat="server">
    <% Html.RenderPartial("_sayHello"); %>
</asp:Content>
<asp:Content runat="server" ID="Page" ContentPlaceHolderID="PageContent">
    <div id="page-head" class="page-head">

        <img alt="diaryWork" height="128" src="../../Content/icons/diaryWork.png" style="width: 48px;
            height: 48px;" width="128" />
        <span id="txtDailyTitle" class="title"></span>
        <div style="margin-top: 5px; min-height: 20px;">
            <div style="float: left;">
                <a id="preDay">前一天</a>
            </div>
            <div style="float: right;">
                <a id="nextDay">后一天</a>
            </div>
        </div>
    </div>
    <div id="page-body">
        <div class="content">
            <div id="divAddWorkItem" style="margin-top: 10px; display: none;">
                <div id="addFinishedWorkitem">
                    添加今天完成的工作任务
                </div>
                <script type="text/javascript">
                    $(function () {
                        $("#addFinishedWorkitem").button({
                            icons: {
                                primary: "ui-icon-circle-plus"
                            },
                            text: true
                        });
                    });
                </script>
            </div>
            <p class="entry-explanation" style="line-height: 35px;">
                今天完成的任务
            </p>
            <div id="divMyWorkitems" class="tableContainer">
            </div>
            <div style="margin-top: 10px; margin-bottom: 10px;">
                <div id="divDailyWork" style="margin-top: 10px; border-bottom: 1px solid #ccc;">
                    <p id="txtDailyWork">
                    </p>
                </div>
                <div class="divExp" style="margin-top: 10px; display: none;">
                    <textarea id="template" cols="56" rows="6" style="margin-bottom: 10px;"></textarea>
                    <div style="margin-bottom: 10px;">
                        <div id="btnSumbit">
                            提交日志</div>
                        <script type="text/javascript">
                            $(function () {
                                $("#btnSumbit").button({
                                    icons: {
                                        primary: "ui-icon-circle-arrow-n"
                                    },
                                    text: true
                                });
                            });
                        </script>
                        &nbsp;或者&nbsp;<a id="btnCancel">取消</a>
                    </div>
                </div>
            </div>
            <p class="entry-explanation txt-unfinished-workitem" style="line-height: 35px; display: none;">
                没有已经完成的任务
            </p>
            <div id="divNeedToDo" class="tableContainer">
            </div>
        </div>
    </div>
    <div class="page-submit">
    </div>
</asp:Content>
<asp:Content runat="server" ID="PageShortcut" ContentPlaceHolderID="PageShortcut">
</asp:Content>
<asp:Content runat="server" ID="PageFoot" ContentPlaceHolderID="PageFoot">
    <div id="menu-finishWorkitem" style="display: none;">
        <div style="margin: 5px">
                <div>
            所用工时数：<input id="txtHours" class="text" style="width: 100px;" />
        </div>
                <p style="float: right;">
            <div id="btnFinish">完成工作任务</div>
            <script type="text/javascript">
                $(function () {
                    $("#btnSumbit").button({
                        icons: {
                            primary: "ui-icon-circle-check"
                        },
                        text: true
                    });
                });
            </script>
        </p>
        </div>
    </div>
    <div id="tip_Remind" style="display: none;">
        <h1>
            小贴士:</h1>
        <p class="indent">
        </p>
    </div>
    <div>
        <% Html.RenderPartial("_workitemCreatorSimple"); %>
    </div>
</asp:Content>
